package com.xnewtech.xplatform.swan.system.modular.log.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xnewtech.xplatform.swan.libs.scanner.annotation.GetResource;
import com.xnewtech.xplatform.swan.libs.scanner.annotation.PostResource;
import com.xnewtech.xplatform.swan.libs.scanner.stereotype.ApiResource;
import com.xnewtech.xplatform.swan.model.web.response.ResponseData;
import com.xnewtech.xplatform.swan.model.web.response.SuccessResponseData;
import com.xnewtech.xplatform.swan.system.modular.log.model.result.AuthLoginLogResult;
import com.xnewtech.xplatform.swan.system.modular.log.param.SysOpLogParam;
import com.xnewtech.xplatform.swan.system.modular.log.service.SysOpLogService;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 系统日志控制器
 *
 * @author xnew
 * @date 2020/3/19 21:14
 */
@RestController
@ApiResource(name = "日志管理")
public class SysLogController {

    @Resource
    private SysOpLogService sysOpLogService;

    /**
     * 查询操作日志
     *
     * @author xnew
     * @date 2020/3/20 18:52
     */
    @GetResource(name = "操作日志_查询", path = "/sysOpLog/page")
    public ResponseData opLogPage(SysOpLogParam sysOpLogParam) {
        return new SuccessResponseData(sysOpLogService.page(sysOpLogParam));
    }

    /**
     * 清空操作日志
     *
     * @author xnew
     * @date 2020/3/23 16:28
     */
    @PostResource(name = "操作日志_清空", path = "/sysOpLog/delete")
    public ResponseData opLogDelete() {
        sysOpLogService.delete();
        return new SuccessResponseData();
    }


    /**
     * 查询登录日志
     * 暂不迁移
     * @author xnew
     * @date 2020/3/20 18:52
     */
    @GetResource(name = "登录日志_查询", path = "/authLoginLog/pageList")
    public ResponseData loginLogPage(@RequestParam(value = "account", required = false) String account) {
        Page pageList = sysOpLogService.pageList(account);
        return new SuccessResponseData(pageList);
    }
    @GetResource(name = "登录日志_详情", path = "/authLoginLog/detail")
    public ResponseData detail(@RequestParam("loginLogId") Long loginLogId) {
        AuthLoginLogResult detail = this.sysOpLogService.detail(loginLogId);
        return ResponseData.success(detail);
    }
}
